<?php
if(!defined('DCS_ROOT')) {exit('Access Denied');}

class RatingModel {
	var $DB;
	function RatingModel ( $DB ){
		$this->DB = $DB;
	}

	function getMovie($id){
		$sql = "SELECT * FROM movie WHERE id = '$id' ";
		$this->DB->query($sql);
		return $this->DB->fetchRow();	
	}
	
	function getTwoWeekComments($mid){
		$weektime = strtotime(date('Y-m-d',time()))  - 86400 * 14 ;
		$sql = "SELECT type,rating,addtime  FROM movie_comments WHERE mid = '$mid' AND  addtime >= '$weektime' ORDER BY addtime ";
		$this->DB->query($sql);
		return $this->DB->fetchAll();	
	}

	function getTwoWeekReviews($mid){
		$weektime = strtotime(date('Y-m-d',time()))  - 86400 * 14 ;
		$sql = "SELECT rating,addtime FROM movie_review WHERE mid = '$mid' AND  addtime >= '$weektime' ORDER BY addtime ";
		$this->DB->query($sql);
		return $this->DB->fetchAll();	
	}

	function getTwoWeekCommentsByIds($mid){
		$weektime = strtotime(date('Y-m-d',time()))  - 86400 * 14 ;
		$sql = "SELECT mid,type,rating,addtime  FROM movie_comments WHERE mid IN($mid) AND  addtime >= '$weektime' ORDER BY addtime ";
		$this->DB->query($sql);
		return $this->DB->fetchAll();	
	}

	function getTwoWeekReviewsByIds($mid){
		$weektime = strtotime(date('Y-m-d',time()))  - 86400 * 14 ;
		$sql = "SELECT mid,rating,addtime FROM movie_review WHERE mid IN($mid) AND  addtime >= '$weektime' ORDER BY addtime ";
		$this->DB->query($sql);
		return $this->DB->fetchAll();	
	}


}
?>
